/**
 * 时间戳转字符串时间(YYYY-MM-dd HH:mm:ss)
 * @param timestamp 时间戳(单位秒)
 */
function ts2str(timestamp) {
    var padLeftZero = function(num) {
        return [(num <= 9) ? '0' : '', num].join('');
    };
    timestamp = Number(timestamp) * 1000;
    var dt = new Date(timestamp);
    return [
        dt.getFullYear(),
        padLeftZero(dt.getMonth() + 1),
        padLeftZero(dt.getDate())
    ].join('-') + '&nbsp;' +
    [
        padLeftZero(dt.getHours()),
        padLeftZero(dt.getMinutes()),
        padLeftZero(dt.getSeconds())
    ].join(':');
}

/**
 * 判断元素是否在数组中
 * @param elem 元素
 * @param _array 数组
 */
function inArray(elem, _array) {
    for (var i = 0; i < _array.length; i++) {
        if(elem ==_array[i]) {
            return true;
        }
    }
    return false;
}

/**
 * 获取地址栏参数值
 * @param param_key 地址栏参数键名
 */
function getUrlParam(param_key) {
    var arr = window.location.search.replace(/^[\?]/, '').split('&');
    for (var i = 0; i < arr.length; i++) {
        var value = arr[i].replace(/^[^\=]+[\=]/, '');
        if(arr[i].replace(value, '') == param_key + '=') {
            return value;
        }
    }
    return null;
}

/**
 * 生成随机数
 * @param len 结果的长度
 * @param collection 生成随机数的集合
 */
function createRand(len, collection) {
    if(!collection || !(collection instanceof Array)) {
        collection = []
        for(var i = 97; i <= 122; i ++) {
            var char = String.fromCharCode(i);
            collection.push(char)
            collection.push(char.toUpperCase())
        }
        for(var i = 0; i <= 9; i ++) {
            collection.push(i.toString())
        }
    }
    var result = [];
    while(result.length < len) {
        var index = Math.round(Math.random()* collection.length);
        var value = collection[index];
        result.push(value);
    }
    return result.join('');
}

/**
 * 获取星期几字符串
 * @param week_num 星期几(整数)
 */
function getWeek(week_num) {
    var weeks = {
        1: '一',
        2: '二',
        3: '三',
        4: '四',
        5: '五',
        6: '六',
        7: '日'
    };
    return '星期' + weeks[week_num];
}